import { _decorator, Button, Component, Node } from 'cc';
import { BasicComponet } from './BasicComponet';
import { AudioSystem } from '../SystemAudio/AudioSystem';
import { AudioEnum } from '../SystemAudio/AudioEnum';
const { ccclass, property } = _decorator;

@ccclass('BasicUI')
export class BasicUI extends BasicComponet {
    @property
    useClickAudio = true;

    protected onLoad(): void {
        this.useClickAudio && this._addBtnClicAudio();
    }

    private _addBtnClicAudio() {
        const btns = this.node.getComponentsInChildren(Button);
        btns.forEach(e => {
            e.node.on(Node.EventType.TOUCH_END, this._playBtnAudio, this);
        })
    }

    private _playBtnAudio() {
        AudioSystem.playEffect(AudioEnum.BtnClick);
    }

    public show(d?) {
        this.node.active = true;
        this.onEvents();
    }

    public hide(d?) {
        this.node.active = false;
        this.offEvents();
    };

}

